import 'package:flutter/material.dart';

// ignore: must_be_immutable
class CartNumView extends StatefulWidget {
  int num = 1;
  FormFieldSetter<int> showCartNum;
  FormFieldSetter<bool> checkSelect;
  CartNumView({this.num, this.showCartNum});
  @override
  _CartNumViewState createState() => _CartNumViewState();
}

class _CartNumViewState extends State<CartNumView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 30,
      width: 120,
      child: Row(
        children: [
          Container(
            width: 30,
            height: 30,
            child: RaisedButton(
              onPressed: () {
                setState(() {
                  if (widget.num > 0) {
                    widget.num--;
                  }
                  widget.showCartNum(widget.num);
                });
              },
              child: Text(
                "—",
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 20,
                ),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: Text(
              "${widget.num}",
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 12,
              ),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
          Container(
            width: 30,
            height: 30,
            child: RaisedButton(
              onPressed: () {
                setState(() {
                  if (widget.num < 99) {
                    widget.num++;
                    widget.showCartNum(widget.num);
                  }
                });
              },
              child: Text(
                "+",
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 24,
                ),
              ),
            ),
          ),
        ],
      ),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border.all(
          color: Colors.grey,
          width: 0.5,
          style: BorderStyle.solid,
        ),
      ),
    );
  }
}
